Search = {};
var iU={};
Search.init = function(){
    //初始化->航班日期
    Search.setDate($("#flightDate"));  
    //绑定->日期控件
    $("#flightDate").on("click",Search.openDate);                   
    //绑定->查询
    $("#search").on("click",iP.search);     
};
//设置日期、星期
Search.setDate = function(elem){
    var json = iG.getObjItem("flySearch_win","date");
    var year = json.year;
    var month = json.month;
    var day = json.day;
    var date = new Date(year,month - 1,day);
    var d1 = new Date(iG.getYear(),iG.getMonth()-1,iG.getDay());
    var d2 = new Date(year,month-1,day);
    var num = (d2 - d1) / 86400000;
    var tip = "";
    if(num == -1) tip = "昨天";
    if(num == 0) tip = "今天";
    if(num == 1) tip = "明天";
    var act = (tip == "") ? "addClass" : "removeClass";
    elem.find(".date").text(year + "-" + month + "-" + day);
    elem.find(".date").attr("date",JSON.stringify(json)); 
    elem.find(".week").text("周" + iG.getWeek(date));
    elem.find(".dateIs").text(tip)[act]("uhide");
};
//设置日期缓存
Search.setDateCache = function(year,month,day){
    var date = {
        year : year,
        month : month,
        day : day
    }
    iG.setObjItem("flySearch_win","date",date);
};
//打开日期控件
Search.openDate = function(){
    var that = $(this);
    var date = JSON.parse(that.find(".date").attr("date"));
    iG.openDate(date.year,date.month,date.day,function(data){
        Search.setDateCache(data.year,data.month,data.day);
        Search.setDate(that);
    })
};
iU.openWinlb = function(name,data){
    /*if(!iG.checkAuthortization("window",name)){
       uexWindow.open("authorityTip_win",0,"authorityTip_win.html",2,"","","4",280);
        return false;
    }*/
    if(data){
        localStorage.setItem(name,JSON.stringify(data));
    }
    var url = name + ".html";
    //iG.saveOpenWin(name);
    uexWindow.open(name,0,url,2,"","","4",280);
};

//到航班列表
Search.toFlightList = function(condition){
    var data = {
        data : {
            type : condition.type,
            condition : condition.condition
        },
        flyListDateShow:true
    };
    iU.openWinlb("flyList_win",data);    
};
Search.openWin = function(name){
    var url = name + ".html";
    uexWindow.open(name,0,url,0,"","","4",280);
};